package view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import controller.DataBaseInteactor;

import model.Conference;
import model.SubProgramChair;

/**
 * Makes a Frame helps assigning reviewer.
 * 
 * @author Richard Lee
 * @version 61313 
 *
 */
public class AssignReviewerView extends JFrame {
	/**
	 * Default serial version id.
	 */
	private static final long serialVersionUID = -1122761030401986685L;
	
	/**
	 * GUI component.
	 */
	private final JPanel reviewerInput = new JPanel();
	private final JLabel reviewerID = new JLabel("Input Reviewer's Id");
	private final JTextField reviwerField = new JTextField(10);
	private final JButton assignButton = new JButton("Assign");
	private final JButton cancelButton = new JButton("Cancel");
	
	/**
	 * ID of the subprogram chair.
	 */
	private final String id;
	
	/**
	 * Author of the manuscript.
	 */
	private final String author;
	
	/**
	 * Title of the manuscript
	 */
	private final String title;
	
	/**
	 * Conference that user belongs to.
	 */
	private final Conference conf;
	
	/**
	 * Database interactor.
	 */
	private final DataBaseInteactor inteactor;
	
	/**
	 * Constructor.
	 * 
	 * @param theId user id passed in.
	 * @param theAuthor the author of the manuscript wants to assign.
	 * @param theTitle the title of the manuscript wants to assign.
	 * @param theConf the conference user belongs to.
	 * @param theInteactor data base interactor.
	 */
	public AssignReviewerView(String theId, String theAuthor, String theTitle, Conference theConf,
			DataBaseInteactor theInteactor) {
		super("Assign Reviewer");
		id = theId;
		author = theAuthor;
		title = theTitle;
		conf = theConf;
		inteactor = theInteactor;
	}
	
	/**
	 * Combine and add all the GUI component.
	 */
	public void createAssignReviewerView() {
		reviewerInput.add(reviewerID);
		reviewerInput.add(reviwerField);
		reviewerInput.add(assignButton);
		reviewerInput.add(cancelButton);
		this.add(reviewerInput);
		pack();
		setVisible(true);
		setLocationRelativeTo(null);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		actionButton();
	}
	
	/**
	 * Add actions to buttons.
	 */
	public void actionButton() {
		assignButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				SubProgramChair spc = new SubProgramChair(id, inteactor);
				spc.assignManuscript(conf, reviwerField.getText(), author, title);
				dispose();
			}
		});
		
		cancelButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
			}
		});
	}
	
}
